package com.hd.view.action;

import org.apache.commons.lang.StringUtils;

import com.hd.common.Common;
import com.hd.common.DataPage;
import com.hd.persistence.model.Machine;

/**
 * 机器Action
 * @author jiaoyang
 *
 *占不提供删除机器功能
 */
public class MachineAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/*机器ID*/
	private String machineId;
	/*机器*/
	private Machine machine;
	/*寿命张数*/
	private String sheetyOfLife;
	/*鼓使用张数*/
	private String cartridgeSheety;
	/*黑粉使用张数*/
	private String blackPowderSheety;
	/*彩色粉使用张数*/
	private String colorPowderSheety;
	/*载体使用张数*/
	private String carrierSheety;
	/*油墨使用张数*/
	private String printingInkSheety;
	/*版纸使用张数*/
	private String paperboardSheety;
	/*炭粉使用张数*/
	private String carbonPowderSheety;
	/*机器类型标识*/
	private String category;
	/*查询出的机器*/
	private DataPage<Machine> machines;
	/**
	 * 增加新机器
	 * 
	 * @return
	 * @throws Exception
	 */
	public String addNewMachine() throws Exception{
		return SUCCESS;
	}
	
	/**
	 * 保存新机型
	 * 
	 * @return
	 * @throws Exception
	 */
	public String saveNewMachine() throws Exception{
		machine.setSheetyOfLife(Integer.parseInt(sheetyOfLife));
		
		if(!StringUtils.isEmpty(Common.replaceSpace(cartridgeSheety))){
			machine.setCartridgeSheety(Integer.parseInt(Common.replaceSpace(cartridgeSheety)));
		}
		if(!StringUtils.isEmpty(Common.replaceSpace(blackPowderSheety))){
			machine.setBlackPowderSheety(Integer.parseInt(Common.replaceSpace(blackPowderSheety)));
		}
		if(!StringUtils.isEmpty(Common.replaceSpace(colorPowderSheety))){
			machine.setColorPowderSheety(Integer.parseInt(Common.replaceSpace(colorPowderSheety)));
		}
		if(!StringUtils.isEmpty(Common.replaceSpace(carrierSheety))){
			machine.setCarrierSheety(Integer.parseInt(Common.replaceSpace(carrierSheety)));
		}
		if(!StringUtils.isEmpty(Common.replaceSpace(printingInkSheety))){
			machine.setPrintingInkSheety(Integer.parseInt(Common.replaceSpace(printingInkSheety)));
		}
		if(!StringUtils.isEmpty(Common.replaceSpace(paperboardSheety))){
			machine.setPaperboardSheety(Integer.parseInt(Common.replaceSpace(paperboardSheety)));
		}
		if(!StringUtils.isEmpty(Common.replaceSpace(carbonPowderSheety))){
			machine.setCarbonPowderSheety(Integer.parseInt(Common.replaceSpace(carbonPowderSheety)));
		}
		machine.setBlackPowderModel(Common.replaceSpace(machine.getBlackPowderModel()));
		machine.setCarbonPowderModel(Common.replaceSpace(machine.getCarbonPowderModel()));
		machine.setCarrierModel(Common.replaceSpace(machine.getCartridgeModel()));
		machine.setCartridgeModel(Common.replaceSpace(machine.getCartridgeModel()));
		machine.setColorPowderModel(Common.replaceSpace(machine.getColorPowderModel()));
		machine.setPaperboardModel(Common.replaceSpace(machine.getPaperboardModel()));
		machine.setPrintingInkModel(Common.replaceSpace(machine.getPrintingInkModel()));

		memberManager.saveMachine(machine);
		statusTemp = true;
		return SUCCESS;
	}
	
	/**
	 * 查询机器(按机器类别查询)
	 * 
	 * @return
	 * @throws Exception
	 */
	public String listMachine() throws Exception{
		if(StringUtils.isEmpty(category)){
			machines = memberManager.pageQueryMachines(getCurrentPage(), pageSize);
		}else{
			machines = memberManager.pageQueryMachines(Integer.parseInt(category), getCurrentPage(), pageSize);
		}
		setTotalPage(machines.getTotalPageCount());
		return SUCCESS;
	}
	
	/**
	 * 修改机器信息
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editMachine() throws Exception{
		return SUCCESS;
	}
	
	/**
	 * 查看机器
	 * 
	 * @return
	 * @throws Exception
	 */
	public String viewMachine () throws Exception{
		machine = memberManager.getMachine(Long.parseLong(machineId));
		return SUCCESS;
	}
/*=====================get,set方法=================================================*/	
	
	public Machine getMachine() {
		return machine;
	}
	
	public void setMachine(Machine machine) {
		this.machine = machine;
	}

	public String getSheetyOfLife() {
		return sheetyOfLife;
	}

	public void setSheetyOfLife(String sheetyOfLife) {
		this.sheetyOfLife = sheetyOfLife;
	}

	public String getCartridgeSheety() {
		return cartridgeSheety;
	}

	public void setCartridgeSheety(String cartridgeSheety) {
		this.cartridgeSheety = cartridgeSheety;
	}

	public String getBlackPowderSheety() {
		return blackPowderSheety;
	}

	public void setBlackPowderSheety(String blackPowderSheety) {
		this.blackPowderSheety = blackPowderSheety;
	}

	public String getColorPowderSheety() {
		return colorPowderSheety;
	}

	public void setColorPowderSheety(String colorPowderSheety) {
		this.colorPowderSheety = colorPowderSheety;
	}

	public String getCarrierSheety() {
		return carrierSheety;
	}

	public void setCarrierSheety(String carrierSheety) {
		this.carrierSheety = carrierSheety;
	}

	public String getPrintingInkSheety() {
		return printingInkSheety;
	}

	public void setPrintingInkSheety(String printingInkSheety) {
		this.printingInkSheety = printingInkSheety;
	}

	public String getPaperboardSheety() {
		return paperboardSheety;
	}

	public void setPaperboardSheety(String paperboardSheety) {
		this.paperboardSheety = paperboardSheety;
	}

	public String getCarbonPowderSheety() {
		return carbonPowderSheety;
	}

	public void setCarbonPowderSheety(String carbonPowderSheety) {
		this.carbonPowderSheety = carbonPowderSheety;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public DataPage<Machine> getMachines() {
		return machines;
	}

	public void setMachines(DataPage<Machine> machines) {
		this.machines = machines;
	}

	public String getMachineId() {
		return machineId;
	}

	public void setMachineId(String machineId) {
		this.machineId = machineId;
	}
	
	
}
